const http = require('http');
const fs = require('fs')
const path = require('path')
const server = http.createServer()

server.on('request',(req,res)=>{
    const url = req.url;
    let fpath ='';
    if(url === '/'){
        fpath = path.join(__dirname,"/clock/index.html")
    }else{
        fpath = path.join(__dirname,'/clock',url)
    }
    // 读取文件的内容
    fs.readFile(fpath,'utf-8',(err,dataStr)=>{
        // 读取失败
        if(err) return res.end('404 not found') 
        res.end(dataStr)
    })
})

server.listen(80,()=>{
    console.log("server running at http://127.0.0.1")
})